package cn.kinoko.service.ai.gpt;

import cn.kinoko.service.ai.ChatAIService;
import jakarta.annotation.Resource;
import org.springframework.ai.chat.messages.Message;
import org.springframework.ai.chat.messages.SystemMessage;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.openai.OpenAiChatClient;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

import static cn.kinoko.model.ai.chat.SystemTemplate.TRANSLATOR_CHAT_SYSTEM_TEMPLATE;

/**
 * @author kk
 */
@Service
public class ChatGptService implements ChatAIService {

    @Resource
    private OpenAiChatClient openAiChatClient;

    /**
     * 翻译助手
     *
     * @param content 内容
     * @return 返回信息
     */
    @Override
    public String translationAssistant(String content) {
        List<Message> messages = new ArrayList<>();
        // 系统预设
        messages.add(new SystemMessage(TRANSLATOR_CHAT_SYSTEM_TEMPLATE));
        // 用户会话
        messages.add(new UserMessage(content));
        return openAiChatClient.call(new Prompt(messages)).getResult().getOutput().getContent();
    }
}
